package com.tbm.impl.service;

import com.tbm.base.service.JsonService;
import com.tbm.common.util.PageData;
import com.tbm.entity.JsonEntity;
import com.tbm.repository.JsonEntityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/9/13.
 */
@Service
public class JsonServiceImpl implements JsonService {

    @Autowired
    private JsonEntityRepository jsonRepository;

    @Override
    public List<PageData> findAll(Example<JsonEntity> ex, Pageable pageable) {
        Page<JsonEntity> jsonEntities = jsonRepository.findAll(ex,pageable);
        List<PageData> pageList = new ArrayList<>();
        for(JsonEntity jsonEntity : jsonEntities.getContent()){
            PageData pd = new PageData();
            pd.put("jsonId",jsonEntity.getJsonId());
            pd.put("jsonName",jsonEntity.getJsonName());
            pd.put("jsonParameter",jsonEntity.getJsonParameter());
            pd.put("jsonPath",jsonEntity.getJsonPath());
            pageList.add(pd);
        }
        return pageList;
    }

    @Override
    public int count() {
        return (int) jsonRepository.count();
    }

}
